﻿$.extend(ksg.ui.widgetMap, {
	/**
	* @name scsArticles
	* @field 
	*/
	"ksg-articles": function ($el, options) { $el.articleListDisplay(options); },
	"ksg-asp-articles": function ($el, options) {
		var cc = new ClientControl($el.get(0), setCpxBizObjListState, getCpxBizObjListState);
		var bizProc = bizProcManager.getBizProc(options.parentBizProc);
		if (bizProc != null) {
			bizProc.addClientControl(cc);
			cc.template = options.template;
			cc.getBizObjState = boL_getBizObjState;
			cc.getBizObjElement = boL_getBizObjElement;
			cc.prCh = boL_prCh;
			cc.isUpdateable = false;
			if(options.isUpdateable)
				cc.isUpdateable = options.isUpdateable;
			cc.maxElements = options.maxElements;
			cc.hasArtForm = options.hasArtForm;
		}
	},
	"ksg-asp-bizobj": function ($el, options) {
		var bizProc = bizProcManager.getBizProc(options.parentBizProc);
		if (bizProc != null) {
			var cc = new ClientControl($el.get(0), setBizObjDetailsState, getBizObjDetailsState);
			bizProc.addClientControl(cc);
			cc.uiFields = options.fields;
			cc.pushChildValues = function (bizobj) {
				for (var i = 0; i < this.uiFields.length; i++) {
					var f = ksg.ui.fields[this.uiFields[i].t];
					if(f)
						f.setVal($('#' + this.uiFields[i].id), bizobj.getAttribute(this.uiFields[i].n));
					else {
						alert("pushChildValues: Cannot find field type: " + this.uiFields[i].t);
					}
				}
			}
			cc.pullChildValues = function (bizobj) {
				for (var i = 0; i < this.uiFields.length; i++) {
					var f = ksg.ui.fields[this.uiFields[i].t];
					if(f) {
						var v = f.getVal($('#' + this.uiFields[i].id));
						if(v != null)
							bizobj.setAttribute(this.uiFields[i].n, v);
					}
					else {
						alert("pullChildValues: Cannot find field type: " + this.uiFields[i].t);
					}
				}
			}
		}
	},
	"ksg-asp-menu": function ($el, options) {
		var c = new ClientControl($el.get(0), setMenuState, getMenuState);
		var bizProc = bizProcManager.getBizProc("SyrinxMenu");
		if (bizProc != null)
			bizProc.addClientControl(c);
	},
	"ksg-asp-actionButton": function ($el, options) {
		var c = new ClientControl($el.get(0), setActionButtonState, getActionButtonState);
		if (options.visible == false)
			$el.hide();
		var bizProc = bizProcManager.getBizProc(options.parentBizProc);
		if (bizProc != null)
			bizProc.addClientControl(c);
	}
});

//-----------

function parseUsaDate(date) {
    return new Date(date.replace(/^(\d+).(\d+).(\d+).(.*)$/, "$3/$1/$2 $4"));
};

function toUsaDate(date) {
    if (nitobi.base.DateMath.invalid(date)) {
        return "";
    }
    var pz = nitobi.lang.padZeros;
    return pz(date.getMonth() + 1) + "-" + pz(date.getDate()) + "-" + date.getFullYear();
};

//-----------

function getBizObjFromControl(clientId) {
    var docEl = nitobi.xml.createXmlDoc('<BizObj />').documentElement;
    eval("updateBizObj" + clientId + "(docEl);");
    return docEl;
}
function updateControlFromBizObj(clientId, bizobj) {
    eval("showBizObj" + clientId + "(bizobj);");
}

//-----------

function setComboSelectedRowByKey(combo, key) {
    var ds = combo.GetList().GetXmlDataSource();
    var numRows = ds.GetNumberRows();
    var setVal = false;
    for (var p = 0; p < numRows; p++)
        if (ds.GetRow(p)[0] == key) {
            $ntb(combo.GetId() + 'SelectedRowIndex').value = p;
            combo.GetList().SetSelectedRow(p);
            combo.SetTextValue(ds.GetRow(p)[1]);
            setVal = true;
            break;
        }
    if (!setVal)
        combo.SetTextValue(key);

}
function getComboSelectedRowKey(combo) {
    var fld = $ntb(combo.GetId() + 'SelectedValue0');
    return fld.value;
    //	var ds =combo.GetList().GetXmlDataSource();	
    //	var index = combo.GetList().GetSelectedRowIndex();
    //	if(index == -1)
    //		index = window.document.getElementById(combo.GetId()+'SelectedRowIndex').value;
    //	var numRows = ds.GetNumberRows();
    //	return (index == null || index < 0 || numRows == 0)?null:ds.GetRow(index)[0];
}

function setComboState(stateEl) {
    var refresh = stateEl.getAttribute('refresh');
    if (refresh != null && this.dhtmlObj.GetMode() != "unbound") {
        var cl = this.dhtmlObj.GetList();
        cl.Clear();
        cl._syx = this;
        cl.GetPage(0, 50, null, 0, null, function (EBAComboSearchNewRecords, list) {
            //setSelectedRowByKey(list._syx.dhtmlObj,list._syx.lastKey);
        });
    }
}

function getComboState(stateEl) {
    //	var lastKey = getSelectedRowKey(this.dhtmlObj);
    //	if((lastKey == null || lastKey.length == 0) && this.lastKey != null)
    //		lastKey = this.lastKey;
    //	//stateEl.setAttribute('selected', lastKey);
    //	stateEl.setAttribute('selected', this.dhtmlObj.GetList().GetSelectedRowIndex());
}


//-----------------
function setInnerHtmlWithScript(element, html) {
    document.getElementById(element).innerHTML = html;

    var re = /<script\b[\s\S]*?>([\s\S]*?)<\//ig;
    var match;
    while (match = re.exec(html)) {
        eval(match[1]);
    }
};


var globalEval = function globalEval(src) {
	if(src == null || src.length == 0)
		return;
    if (window.execScript) {
        window.execScript(src);
        return;
    }
    var fn = function () {
        window.eval.call(window, src);
    };
    fn();
};


//--- ExtendedGrid.js --------
var oldExtendedSetupGrid = null;
if (typeof(extendedSetupGrid) != "undefined")
    oldExtendedSetupGrid = extendedSetupGrid;

extendedSetupGrid = function (grid) {
    oldExtendedSetupGrid(grid);
    var bizProc = eval(eval(grid.ID + "ParentBizProc"));
    if (bizProc != null) {
        for (var pos = 0; pos < bizProc.ClientControls.length; pos++)
            if (bizProc.ClientControls[pos].id == grid.ID)
                return;

        grid.ClientControl = new ClientControl(grid, setGridState, getGridState);
        grid.ClientControl.id = grid.ID;
        bizProc.addClientControl(grid.ClientControl);
        grid.BizProc = bizProc;
    }
}
oldExtendedSetupGrid = extendedSetupGrid;

function setGridState(stateEl) {
    var g = this.dhtmlObj;
    if (stateEl.getAttribute('refresh') != null) {
        //this.dhtmlObj.refresh();
        var scrollPos = $ntb(g.ID + "_ScrollInfo").value;
        var rc = stateEl.getAttribute('rowCount');
        rc = new Number(rc);

        g.clearData();
        g.clearSurfaces();
        if (scrollPos != "NaN,NaN")
            g.subscribeOnce('DataReady', function () {
                try {
                    g.rowCount = rc;
                    g.setRowCount(rc);
                    g.setupGridScrollPosition(scrollPos);
                    window.setTimeout(function () {
                        g.setRowCount(rc); g.setupGridScrollPosition(scrollPos); g.activeCellObject = null; g.activeCell = null;
                    }, 50);
                } catch (e) { }
            }, null, new Array());
        g.dataBind();
    }
    else if (stateEl.getAttribute('rowCount') != null) {
        var rc = stateEl.getAttribute('rowCount');
        g.knownRowCount = rc;
        g.setRowCount(rc);
    }
	try{resizeWin();}catch(e){}
}

function getGridState(stateEl) {
    var hiddenField = document.getElementById(this.id + "_SelRowInfo");
    stateEl.setAttribute('selectedRows', hiddenField.value);

    if (this.dhtmlObj.datatable.log.selectNodes("//" + nitobi.xml.nsPrefix + "data/*").length != 0) {
        stateEl.setAttribute('updates', this.dhtmlObj.datatable.log.xml);
        this.dhtmlObj.datatable.flushLog();
    }
}

function gridCellFocus(eventArgs) {
    var grid = eventArgs.getSource();
    var cell = eventArgs.getCell();
    var row = cell.getRow();
    if (grid.syrinxLastRow != row) {
        grid.syrinxLastRow = row;
        if (grid.datatable.log.selectNodes("//" + nitobi.xml.nsPrefix + "data/*").length != 0) {
            grid.BizProc.triggerEvent(grid.ClientControl.id, 'bizObjUpdated', this.dhtmlObj.datatable.log.xml);
            this.dhtmlObj.datatable.flushLog();
        }
    }
}

function gridCellEditComplete(eventArgs) {
    try {
        if (eventArgs.getEvent().type == "blur" || eventArgs.getEvent().type == "keydown") {
            var cell = eventArgs.getCell();
            var col = cell.getColumn();
            var row = cell.getRow();
            var grid = eventArgs.getSource();
            var backward = eventArgs.getEvent().shiftKey;
            var keyCode = eventArgs.getEvent().keyCode;
            //var realBlur = true;
            var doUpdate = false;


            if (eventArgs.getEvent().type == "blur") {
                var lastKey = -1;
                try { lastKey = grid.cellEditor.lastKeyCode; } catch (e) { }
                if (lastKey == 13)
                    doUpdate = true;
            }
            else if (keyCode == 38 || keyCode == 40 || keyCode == 13)
                doUpdate = true;

            if (doUpdate && grid.datatable.log.selectNodes("//" + nitobi.xml.nsPrefix + "data/*").length != 0) {
                grid.BizProc.triggerEvent(grid.ID, 'bizObjUpdated', grid.datatable.log.xml);
                grid.datatable.flushLog();
            }
        }
    }
    catch (e) { }
}

function getSelectedRowAsJSON(gridId) {

}

function getGridRowInfo(gridId) {
    var g = nitobi.getComponent(gridId);
    var r = g.getSelectedRow();
    var c = g.columnCount();
    if (r == -1 || c == -1)
        return null;

    var docEl = nitobi.xml.createXmlDoc('<BizObj />').documentElement;
    for (var p = 0; p < c; p++) {
        var v = "";
        if (g.getColumnObject(p).getModel().getAttribute("editor") == "IMAGE")
            v = g.getCellValue(r, p);
        else {
            v = g.getCellText(r, p).replace(/&nbsp;/g, " ");
            if (v.match(/^\s*$/) != null)
                v = "";
        }
        docEl.setAttribute(g.getColumnObject(p).getModel().getAttribute("ColumnName"), v);
    }
    return docEl;
}
function updateGridRowInfo(gridId, bizobj) {
    if (bizobj == null)
        return;
    var g = nitobi.getComponent(gridId);
    var r = g.getSelectedRow();
    var c = g.columnCount();
    for (var p = 0; p < c; p++) {
        var n = g.getColumnObject(p).getModel().getAttribute("ColumnName");
        var a = bizobj.getAttributeNode(n);
        var nt = g.getColumnObject(p).getModel().getAttribute("editor");
        if (a != null && nt != "LISTBOX" && nt != "CHECKBOX")
            g.getCellObject(r, p).setValue(a.value, a.value);
    }
}

//--- GOgleMapGlobalScript.js
function setGMapState(stateEl) {
    try {
        var html = stateEl.getAttribute('html');
        if (html != null && html != '')
            this.dhtmlObj.innerHTML = html;

        var script = stateEl.getAttribute('script');
        if (script != null && script.length > 0)
            eval(script);
    } catch (e) { }
}
function getGMapState(stateEl) {
}

//--- EditImage.js --- 
function setScsImage(img, baseDir) {
    var media = window.showModalDialog(baseDir + "/popups/InsertImagePopup.aspx?T=Insert Image", null, "dialogWidth:750px;dialogHeight:500px;center:yes; resizable: yes; help: no");
    if (media != false && media != null) {
        $("#" + img).attr('src', media.mediaUrl);
    }
}

function clearScsImage(img) {
    $("#" + img).attr('src', '');
}

function getScsImageSrc($img, fullName) {
    var x = $img.attr('src');
    if (!fullName) {
        var r = x.match(/.*?\img\/[^\/]+\/[^\/]+\/(.*)$/);
        if (r != null)
            x = r[1];
    }
    if (x.toLowerCase() == "/images/blank.gif")
        x = "";
    return x;
}

//--- ArtForms.js
function findArtFormData(parentNames) {
    var names = parentNames.split(',');
    for (var c = 0; c < names.length; c++) {
        var parentElement = $ntb(names[c]);
        if (parentElement != null)
            return getArtFormData(parentElement);
    }
}
function getArtFormData(parentElement, el) {
    if (typeof validateFormFields == 'function')
        validateFormFields();

    if (el == null) {
        var doc = nitobi.xml.createXmlDoc('<ArtForm />');
        el = doc.documentElement;
    }
    addFormElements(parentElement, el);
    return el.xml;
}

function addFormElements(parentElement, docEl) {
    if (parentElement.hasChildNodes()) {
        var children = parentElement.childNodes;
        for (var i = 0; i < children.length; i++) {
            var child = children[i];
            if (child.nodeName.toUpperCase() == "INPUT") {
                var title = child.title;
                //docEl.setAttribute("InputType", child.type.toLowerCase());
                if (child.type.toLowerCase() == "checkbox") {
                    if (child.checked)
                        docEl.setAttribute(child.name, "true");
                    else
                        docEl.setAttribute(child.name, "false");

                }
                else if (child.type.toLowerCase() == "radio") {
                    if (child.checked)
                        docEl.setAttribute(child.name, child.value);
                }
                else
                    docEl.setAttribute(child.name, child.value);
                docEl.setAttribute(child.name + ".title", title);
            }
            else if (child.nodeName.toUpperCase() == "TEXTAREA") {
                //docEl.setAttribute("InputType", child.nodeName.toLowerCase());
                docEl.setAttribute(child.name, child.value);
            }
            else if (child.nodeName.toUpperCase() == "SELECT") {
                var v = child.value;
                if ((v == null || v == "") && child.selectedIndex > 0)
                    v = child.options[child.selectedIndex].text;

                docEl.setAttribute(child.name, v);
            }
            else
                addFormElements(child, docEl);
        }
    }

}

function showArtFormData(parentElement, xml) {
    if (xml == null || xml.length == 0)
        return;
    var doc = nitobi.xml.createXmlDoc(xml);
    var docEl = doc.documentElement;
    setupFormElements(parentElement, docEl);
    if (typeof setupFormFields == 'function')
        setupFormFields();
}

function setupFormElements(parentElement, docEl) {
    if (parentElement.hasChildNodes()) {
        var children = parentElement.childNodes;
        for (var i = 0; i < children.length; i++) {
            var child = children[i];
            var attrib = findXmlAttributeFromBaseName(child.name, docEl);
            // if(child.name != null && child.name != "" && docEl.getAttribute(child.name) != null)
            if (attrib != null) {
                if (child.nodeName.toUpperCase() == "INPUT") {
                    if (child.type.toLowerCase() == "checkbox") {
                        if (attrib.value == "true")
                            child.checked = true;
                        else
                            child.checked = false;
                        //child.checked = docEl.getAttribute(child.name)
                    }
                    else if (child.type.toLowerCase() == "radio") {
                        if (attrib.value == child.value)
                            child.checked = true;
                    }
                    else
                        child.value = attrib.value;
                }
                else if (child.nodeName.toUpperCase() == "TEXTAREA")
                    child.value = attrib.value;
                else if (child.nodeName.toUpperCase() == "SELECT")
                    for (var p = 0; p < child.options.length; p++)
                        if (child.options[p].value == attrib.value || child.options[p].text == attrib.value) {
                            child.options[p].selected = true;
                            child.selectedIndex = p;
                            break;
                        }
                        else
                            setupFormElements(child, docEl);
            }
            else
                setupFormElements(child, docEl);
        }
    }

}

function findXmlAttributeFromBaseName(baseName, docEl) {
    if (baseName != null && baseName.length > 0) {
        var attribs = docEl.attributes;
        for (var p = 0; p < attribs.length; p++)
            if (attribs[p].name == baseName || (attribs[p].name.length < baseName.length && baseName.substr(0, attribs[p].name.length) == attribs[p].name))
                return attribs[p];
    }
    return null;
}

function addCommas(nStr) {
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2;
}


//--- JQueryBaseLibrary.js ----
jQuery.cookie = function (key, value, options) {

    // key and value given, set cookie...
    if (arguments.length > 1 && (value === null || typeof value !== "object")) {
        options = jQuery.extend({}, options);

        if (value === null) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? String(value) : encodeURIComponent(String(value)),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};



//--- ReadOnly.js ---
var globalEditChanges = false;
function navTo(evt) {
    var el = evt.srcElement;
    if (evt.altKey && el.contentEditable == "true")
        window.location.href = el.href;
}

function getROCTextValue(el) {
    var acEl = ($(el).children().length == 1 && $(el).children().first().attr('tagName') == 'A') ? $(el).children().first() : $(el);
    if (acEl.attr("contentEditable") == "true" && (acEl.attr("scsChanged") == "true" || acEl.attr("scsChanged") == true))
        return acEl.html();
    return null;
}

var notEditKeys = [9, 11, 17, 35, 36, 37, 38, 39, 49];
function isNoEditKey(k) {
    for (var p = 0; p < notEditKeys.length; p++)
        if (notEditKeys[p] == k)
            return true;
}

function fldChange(evt) {
    if (typeof (disableGlobalEditChanges) != "undefined" && bizProcManager.inEvent == true ||
        (typeof (disableGlobalEditChanges) != "undefined" && disableGlobalEditChanges == true))
        return;
    if (evt.type == "change" || (evt.type == "keydown" && !isNoEditKey(evt.keyCode))) {
        var el = evt.srcElement;
        if (el == null)
            el = evt.target;
        globalEditChanges = true;
        if (el != null)
            $(el).attr("scsChanged", true);
    }
}

function setupListeners() {
    $("input, textarea, select").each(function () {
        var t = $(this);
        if (!t.hasClass('notInEdit') && !this.id != null && this.id.match(/^__/) == null && this.scslis == null &&
                (this.type == null || this.type != "hidden") && t.closest(".notInEdit").length == 0) {
            t.change(function (e) { fldChange(e); });
            this.scslis = true;
        }
    });
    $(".CEDit").each(function () {
        if (!$(this).hasClass('notInEdit') && this.scslis == null) {
            $(this).keydown(function (e) { fldChange(e); });
            this.scslis = true;
        }
        if (this.tagName == "A")
            $(this).click(function (e) { { navTo(e); } });
    });
}

//$(window).unload(function () {
$(window).bind('beforeunload', function () {
    if (globalEditChanges) {
        globalEditChanges = false;
        if (confirm("You have unsaved changes.  Would you like to save them before navigating away?"))
            bizProcManager.triggerEvent(null, new EventInfo("globalEdit", "updateBizObj"), true);
    }
});
var confirmSave = null;
$(window).load(function () {
    if (typeof (disableGlobalEditChanges) != "undefined" && disableGlobalEditChanges == true)
        return;
    setupListeners();
	if(typeof (bizProcManager) != "undefined") {
		bizProcManager.addAfterAjaxEventHandler(function (doc, eventInfo) {
			if ((eventInfo.eventId != null && eventInfo.eventId.match(/_update$/) != null) ||
				(eventInfo.ctlId != null && eventInfo.ctlId.match(/_update$/) != null))
				globalEditChanges = false;
			setupListeners();
		});

		bizProcManager.addBeforeAjaxEventHandler(function (bizProc, eventInfo) {
			if ((eventInfo.eventId == "bizObjSelected" || eventInfo.eventId == "gm1") && globalEditChanges) {
				if (confirm("You have unsaved changes.  Would you like to save them before navigating away?")) {
					bizProcManager.triggerEvent(null, new EventInfo("globalEdit", "updateBizObj"), true);
					globalEditChanges = false;
				}
				else
					globalEditChanges = false;
			}
		});
	}
	ksg.App.bizProcMgr.addActionTriggerObserver({
		completed: function(actionStr) {
			if(actionStr.match(/update/i))
				globalEditChanges = false;
		}
	});
});

//--- ComplexBizObjListDisplay.cs ---
function checkAll(fromEl, onOff) {
    var els = document.getElementsByTagName('input');
    for (var c = 0; c < els.length; ++c)
        if (els[c].id.length > fromEl.length && els[c].id.substring(0, fromEl.length) == fromEl)
            els[c].checked = onOff;
}

function boL_getBizObjState(stateEl) {
    this.prCh(this.dhtmlObj, stateEl);
}

function boL_prCh(el, stateEl) {
    var idPat = /(.*)_(\d+)_(\d+)$/;
    var idPat2 = /(.*)_(\d+)$/;
    var cs = el.childNodes;
    for (var i = 0; i < cs.length; i++) {
        var c = cs[i];
        var id = c.id;
        if (id != null && id.match(idPat) != null) {
            var fieldName = findUniquePart(RegExp.$1, RegExp.$1);
            var row = RegExp.$2;
            var typeIndex = RegExp.$3;
            var bizObj = this.getBizObjElement(stateEl, row);
            try {
                var val = BizObjFieldTypes[typeIndex].script(c);
                if (val != null)
                    bizObj.setAttribute(fieldName, val);
            } catch (e) { }
        }
        else if (this.hasArtForm == true && $(c).hasClass('ArtForm') && id.match(idPat2) != null) {
            var row = RegExp.$2;
            var bizObj = this.getBizObjElement(stateEl, row);
            var fieldName = findUniquePart(RegExp.$1, RegExp.$1);
            var af = bizObj.ownerDocument.createElement(fieldName);
            bizObj.appendChild(af);
            getArtFormData(c, af);
        }
        else
            this.prCh(c, stateEl);
    }
}

function findUniquePart(fullId, shorterId) {
    try {
        var pos = shorterId.lastIndexOf('_');
        if (pos != -1) {
            var shorterId = shorterId.substr(0, pos);
            if (nitobi.html.getElement(shorterId) != null)
                return fullId.substr(pos + 1);
            else
                return findUniquePart(fullId, shorterId);
        }
        return fullId;
    }
    catch (err) {
        var x = err;
    }
}

function setCpxBizObjListState(stateEl) {
    this.template = stateEl.getAttribute('template');
    var html = stateEl.getAttribute('html');
    if (html != null && html != '')
        this.dhtmlObj.innerHTML = html;

    var script = stateEl.getAttribute('script');
    eval(script);
}

function getCpxBizObjListState(stateEl) {
    stateEl.setAttribute('template', this.template);
    stateEl.setAttribute('maxElements', this.maxElements);
    if (this.isUpdateable)
        this.getBizObjState(stateEl);
}

function boL_getBizObjElement(stateEl, rowNum) {
    var bizObj = stateEl.selectSingleNode('BizObj[@_row = \'' + rowNum + '\']');
    if (bizObj == null) {
        bizObj = stateEl.ownerDocument.createElement('BizObj');
        bizObj.setAttribute('_row', rowNum);
        stateEl.appendChild(bizObj);
    }
    return bizObj;
}

var BizObjFieldTypes = [
	{ type: 'textbox', script: function (dhtmlEl) { return dhtmlEl.value; } },
	{ type: 'hiddenfield', script: function (dhtmlEl) { return dhtmlEl.value; } },
	{ type: 'checkbox', script: function (dhtmlEl) { return dhtmlEl.checked ? 'True' : 'False'; } },
	{ type: 'dropdowncalendar', script: function (dhtmlEl) { return nitobi.html.getElement(dhtmlEl.id + 'Fld').value; } },
	{ type: 'nitobicomboboxbizobjlistdisplay', script: function (dhtmlEl) { return getSelectedRowKey(nitobi.getComponent(dhtmlEl.id + '_cm')); } },
    { type: 'combo', script: function (dhtmlEl) { return $ntb(dhtmlEl.id + 'SelectedValue0').value; } },
	{ type: 'radiobutton', script: function (dhtmlEl) { return dhtmlEl.checked ? 'True' : 'False'; } },
    { type: 'dropdownlist', script: function (dhtmlEl) { return dhtmlEl.options(dhtmlEl.selectedIndex).value; } },
    { type: 'editableimage', script: function (dhtmlEl) { var x = dhtmlEl.src; var i = x.indexOf('/img/'); if (i > 0) x = x.substr(i); return x; } },
	{ type: 'readonlytext', script: function (dhtmlEl) { return getROCTextValue(dhtmlEl) } }
];


//--- NitobiBizObjDisplay.cs ---
function setBizObjDetailsState(stateEl) {
    //var newMe = eval(this.id + 'cc');
    var html = stateEl.getAttribute('html');
    if (html != null && html != '') {
        this.dhtmlObj = $(html).replaceAll($(this.dhtmlObj)).get(0);
        var options = $(this.dhtmlObj).data("options");
        this.uiFields = options.fields;
    }


    var script = stateEl.getAttribute('script');
    globalEval(script);
    var bizObj = stateEl.selectSingleNode('BizObj');
    if(bizObj)
        this.pushChildValues(bizObj);

//    var procs = bizProcManager.bizProcs;
//    var c = null;
//    for (var bps in procs)
//        if (bps != 'toJSONString' && (procs[bps].ClientControls.length == 0 || (c = nitobi.html.getElement(procs[bps].ClientControls[0].id)) == null || c.parentNode == null)) {
//            procs[bps].dead = true;
//        }

//    var newBps = new Array();
//    for (var bps in bizProcManager.bizProcs)
//        if (bps != 'toJSONString' && !procs[bps].dead)
//            newBps.push(procs[bps]);
//    bizProcManager.bizProcs = newBps;

    //TODO: This should be in ArticleTranslationDisplay, but for now its here.
    var formData = stateEl.getAttribute('formData');
    if (formData != null)
        showArtFormData(this.dhtmlObj, formData);


}

function getBizObjDetailsState(stateEl) {
    var bizobj = stateEl.ownerDocument.createElement('BizObj');
    stateEl.appendChild(bizobj);
    if (this.pullChildValues != null)
        this.pullChildValues(bizobj);
}

//--- NitobiPaginationDisplay.cs ---
function setPaginationState(stateEl) {
    try {
        var html = stateEl.getAttribute('html');
        if (html != null && html != '')
            this.dhtmlObj.innerHTML = html;
    } catch (e) { }
}
function getPaginationState(stateEl) {
}


//--- OldAnimi.js ---
function animi(pname, it, fs, dt) {
    this.prt = document.getElementById(pname);
    this.pos = -1;
    this.dt = dt; this.it = it;
    this.dp = 0; this.fs = fs;
    eval(pname + "a=this");
}
animi.prototype.go = function () {
    var lp = this.pos, prt = this.prt, chlds = $(prt).find("." + this.it); //childNodes;
    if (chlds.length <= 1) {
        chlds.css("display", "block");
        return;
    }
    for (var p = ((lp >= chlds.length - 1) ? -1 : lp) + 1; p < chlds.length; p = (p == chlds.length - 1) ? 0 : p + 1) {
        var c = chlds.eq(p);
        if (lp >= 0) chlds.eq(lp).fadeOut(this.fs);
        c.css("top", "0px").css("display", "none");
        c.fadeIn(this.fs);
        this.pos = p;
        setTimeout(prt.id + "a.go()", this.dt[this.dp]); this.dp++;
        if (this.dp == this.dt.length) this.dp = 0;
        return;
    }
}

//--- menu startup ---
function setMenuState(stateEl) {
    try {
        var html = stateEl.getAttribute('html');
        if (html != null && html != '') {
            $('#' + this.id).replaceWith(html);
            setupMenuEvents();
        }
    } catch (e) { }
}
function getMenuState(stateEl) {

}

//--- Action Button ---
function setActionButtonState(stateEl) {
    try {
        this.dhtmlObj.disabled = stateEl.getAttribute('enabled').toLowerCase() == 'true' ? false : true;
        this.dhtmlObj.style.display = stateEl.getAttribute('visible').toLowerCase() == 'true' ? 'inline' : 'none';
        var label = stateEl.getAttributeNode('label');
        if (label != null)
            this.dhtmlObj.innerHTML = label.text;
    } catch (e) { }
}
function getActionButtonState(stateEl) {
    try { stateEl.setAttribute('action', this.dhtmlObj.name); } catch (e) { }
}

$(document).ready(function () {
    $(".searchField").keydown(function (e) {
        if (e.which == 13) {
            $('.SearchBtn').click();
        }
    }).click(function () {
        this.select();
    });
});


